﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;
using System.Security;

namespace Business.ReadAPI.Application.Foods
{
    public class FoodQueryRequestHandler : IRequestHandler<FoodQueryRequestModel, APIResult>
    {
        private IBaseRepository<Food> foodRepository;
        private readonly IMapper mapper;
        public FoodQueryRequestHandler(IBaseRepository<Food> foodRepository, IMapper mapper)
        {
            this.foodRepository = foodRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(FoodQueryRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.SearchSuccess;
            result.Msg = "查询成功";

            var list = foodRepository.GetAll();
            List<FoodQueryResponseModel> permissions = mapper.Map<List<FoodQueryResponseModel>>(list);
            result.Data = permissions;

            return Task.FromResult(result);
        }
    }
    public class FoodQueryRequestModel:IRequest<APIResult>
    {
    }
    public class FoodQueryResponseModel
    {
        public int FoodId { get; set; }
        public string FoodName { get; set; }
    }
}
